import requests
import random
import decimal


# 生成id
def generate_id():
    id_options = [1, 5, 7, 11, 12]
    return random.choice(id_options)


# 生成price
def generate_price():
    num = random.random()
    if num < 0.4:
        price = random.randint(3000, 4000)
    elif num < 0.7:
        price = random.randint(4000, 6000)
    else:
        price = random.randint(6000, 100000)
    return decimal.Decimal(price)


# 生成amount
def generate_amount():
    return random.randint(1, 100)


def test_interface():
    url = "http://www.test.com/order/place"
    data = {
        "id": generate_id(),
        "price": generate_price(),
        "amount": generate_amount()
    }
    response = requests.post(url, json=data)
    response.raise_for_status()
    print("接口请求成功，响应内容:", response.text)


if __name__ == "__main__":
    test_interface()
